export const sleep = (ms) => {
    return new Promise(resolve => {
        setTimeout(() => {
            resolve()
        }, ms)
    })
}

export const to = (promise) => {
    return new Promise(resolve => {
        promise.then(res => {
            resolve([null, res])
        }).catch(err => {
            console.log(err)
            resolve([err, null])
        })
    })
}

export const formatSearch = (search) => {
    let paramsString = search.substring(1)
    let obj = {}
    paramsString.split('&').forEach(item => {
        item.split('=').reduce((pre, current, index) => {
            if(index % 2 === 1) obj[pre] = current
            return current
        })
    })
    return obj
}